package com.vecchio.uitl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
	private static final String DriverClassName = "com.mysql.jdbc.Driver";
	private static final String DataBaseUrl = "jdbc:mysql://127.0.0.1:3306/db_diary?characterEncoding=utf-8";
	private static final String DataBaseUserName = "root";
	private static final String DataBasePassword = "wzl8715";
	public static Connection getConnection() throws Exception{
		Class.forName(DriverClassName);
		Connection connection = DriverManager.getConnection(DataBaseUrl, 
				DataBaseUserName,
				DataBasePassword);
		return connection;
	}
	
	public static void closeCon(Connection connection) throws SQLException {
		if (connection != null) {
			connection.close();
		}
	}
	
	public static void main(String[] args) {
		try {
			DBUtil.getConnection();
			System.out.println("ok");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("no");
		}
	}
}
